package com.whmall.service.crm.module.companycertificatechemical.impl;

import com.whmall.component.entity.dto.PageReqDTO;
import com.whmall.component.entity.dto.PageRspDTO;
import com.whmall.service.crm.entity.dto.companycertificatechemical.CompanyCertificateChemicalQueryReqDTO;
import com.whmall.service.crm.module.companycertificatechemical.CompanyCertificateChemicalApproveQueryCriteria;
import com.whmall.service.crm.module.companycertificatechemical.CompanyCertificateChemicalRepository;
import com.whmall.service.crm.module.companycertificatechemical.entity.CompanyCertificateChemicalApproveDO;
import com.whmall.service.crm.module.companycertificatechemical.entity.CompanyCertificateChemicalDO;
import com.whmall.service.crm.module.companycertificatechemical.entity.qo.CompanyCertificateChemicalQO;
import com.whmall.service.crm.module.companycertificatechemical.impl.dao.CompanyCertificateChemicalApproveMapper;
import com.whmall.service.crm.module.companycertificatechemical.impl.dao.CompanyCertificateChemicalMapper;
import com.whmall.service.crm.util.PageDTOHelper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

import java.util.List;

/**
 * CompanyCertificateChemicalRepositoryImpl
 *
 * @author alex
 * @since 2020/8/18
 */
@Repository
@RequiredArgsConstructor
public class CompanyCertificateChemicalRepositoryImpl implements CompanyCertificateChemicalRepository {
    private final CompanyCertificateChemicalMapper companyCertificateChemicalMapper;
    private final CompanyCertificateChemicalApproveMapper companyCertificateChemicalApproveMapper;

    @Override
    public PageRspDTO<CompanyCertificateChemicalDO> findAssociatePage(PageReqDTO pageRequest, CompanyCertificateChemicalQO qo) {
        Assert.notNull(pageRequest, "pageRequest不允许为空");
        Assert.notNull(pageRequest.getPageSize(), "pageSize不允许为空");
        Assert.notNull(pageRequest.getPageNum(), "pageNum不允许为空");
        Assert.notNull(qo.getCompanyId(), "companyId不允许为空");
        PageDTOHelper.startPage(pageRequest);
        List<CompanyCertificateChemicalDO> list = companyCertificateChemicalMapper.listBy(qo);
        return PageDTOHelper.toPageDTO(list);
    }

    @Override
    public PageRspDTO<CompanyCertificateChemicalApproveDO> findApprovePage(PageReqDTO pageRequest, CompanyCertificateChemicalApproveQueryCriteria criteria) {
        Assert.notNull(pageRequest, "pageRequest不允许为空");
        Assert.notNull(pageRequest.getPageSize(), "pageSize不允许为空");
        Assert.notNull(pageRequest.getPageNum(), "pageNum不允许为空");

        PageDTOHelper.startPage(pageRequest);
        List<CompanyCertificateChemicalApproveDO> list = companyCertificateChemicalApproveMapper.listByQueryCriteria(criteria);
        return PageDTOHelper.toPageDTO(list);
    }
}
